package com.japp.sys.web;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.japp.base.BaseAction;
import com.japp.sys.bean.SelectBean;
import com.japp.sys.bean.UserBean;
import com.japp.sys.mapper.DpMapper;
import com.japp.sys.service.UserService;
import com.japp.tools.common.Common;
import com.japp.tools.common.JappLog;
@Scope("prototype")
@Controller
public class UserAction extends BaseAction<UserBean> {
	
	private static final long serialVersionUID = -155730993938501274L;
	@Autowired
	private UserService service;
	@Autowired
	private DpMapper dpMapper;
	private UserBean user = new UserBean();	
	private Map<String, String> map = null;

	/**
	 * 分页查询用户
	 * @return
	 */
	public String queryUser(){
		page = service.getPage(page, user);
		return "queryUser";
	}
	
	public String queryPopupUser(){
		if("ab".equals(result)||"".equals(user.getU_ltd())&&"".equals(user.getU_ltd_code())){
			try {
				List<SelectBean> list = dpMapper.queryDpSelectAll();		//部门
				json_val = Common.formtSelectToJson(list);
			} catch (Exception e) {
				JappLog.log.error("查询部门或转换Json错误",e);
			}
		}
		page = service.getPage(page, user);
		return "userPopup";
	}
	
	
	/**
	 * 查询用户信息
	 * @return
	 */
	public String findUserView(){
		user = service.findUserById(user.getU_id());
		return "findUserView";
	}
	/**
	 * 用户更新
	 * @return
	 */
	public String updateUser(){
		service.updateUser(user);
		return "updateUser";
	}
	/**
	 * 用户更新查询
	 * @return
	 */
	public String findUserDetil(){
		if(user!=null&&user.getU_id()!=0){
			user = service.findUserById(user.getU_id());
		}
		map = service.getRAndDAll();
		return "updateUser";
	}
	
	/**
	 * 更新角色
	 * @return
	 */
	public void updateUserById() {
		int rel = 0;
		if(user.getU_id()!=0){
			rel = service.updateUser(user);
		}
		if(rel==999){
			result = "用户“"+user.getU_name()+"”已存在!";
		}else if(rel!=0){
			result = "用户“"+user.getU_name()+"”修改成功!";
		}else{
			result = "用户“"+user.getU_name()+"”修改失败!";
		}
		wPrint(result);
	}
	/**
	 * 添加角色
	 * @return
	 */
	public void insertUserById() {
		int rel = service.insertUser(user);
		if(rel==999){
			result = "账户名“"+user.getU_login_id()+"”已存在!";
		}else if(rel!=0){
			result = "用户“"+user.getU_name()+"”新增成功!";
		}else{
			result = "用户“"+user.getU_name()+"”新增是失败!";
		}
		wPrint(result);
	}
	/**
	 * 删除角色
	 * @return
	 */
	public void deleteUserById() {
		int rel = service.deleteUser(keys);
		if(rel!=0){
			result = "角色删除成功!";
		}else{
			result = "角色删除失败!";
		}
		wPrint(result);
	}
	/*=========GET SET 开始==========*/

	public UserBean getUser() {
		return user;
	}
	public Map<String, String> getMap() {
		return map;
	}
	public void setMap(Map<String, String> map) {
		this.map = map;
	}
	public void setUser(UserBean user) {
		this.user = user;
	}
	
	/*=========GET SET 结束==========*/
}
